Function.RegisterNamespace("System.IO.DirectoryStrategy");

System.IO.DirectoryStrategy.Rhino=function(){
    // IDirectoryStrategy Members
    this.Exists=function(path){
        if(!!path){
            var file=new java.io.File(System.IO.Path.Normalize(path));
            return file.exists()&&file.isDirectory();
        }
        return false;
    };

    this.GetFiles=function(path){
        var files=[];
        if(this.Exists(path)){
            var directory=new java.io.File(System.IO.Path.Normalize(path));
            var fileList=directory.listFiles();
            for(var i=0;i<fileList.length;i++){
                if(fileList[i].isFile()){
                    files.push(fileList[i].getAbsolutePath()+'');
                }
            }
        }
        return files;
    };
    
    this.GetDirectories=function(path){
        var directories=[];
        if(this.Exists(path)){
            var directory=new java.io.File(System.IO.Path.Normalize(path));
            var directoryList=directory.listFiles();
            for(var i=0;i<directoryList.length;i++){
                if(directoryList[i].isDirectory()){
                    directories.push(directoryList[i].getAbsolutePath()+'');
                }
            }
        }
        return directories;
    };

    // IStrategySpecification Members
    this.IsSatisfiedBy=function(candidate){
        return (typeof(java)!='undefined' && typeof(environment)!='undefined' && typeof(defineClass)=="function" && typeof(loadClass)=="function");
    };
};

System.IO.DirectoryStrategy.Rhino.Implement(System.IO.DirectoryStrategy.IDirectoryStrategy,'System.IO.DirectoryStrategy.Rhino');
System.IO.DirectoryStrategy.Rhino.Implement(System.Script.Strategy.IStrategySpecification,'System.IO.DirectoryStrategy.Rhino');

System.IO.Directory.Strategies.Add(System.IO.DirectoryStrategy.Rhino);